<%@ page contentType="text/html;charset=UTF-8" %>
<%
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + "/";
%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>后台登录</title>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>

    <script type="text/javascript" src="${basePath}js/jquery-3.3.1.min.js"></script>
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="<%=basePath %>css/xadmin.css">
    <script src="<%=basePath %>lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="<%=basePath %>js/xadmin.js"></script>

</head>
<body class="login-bg">

<div class="login layui-anim layui-anim-up">
    <div class="message">北京爱看爱秀教育科技有限公司</div>
    <div id="darkbannerwrap"></div>

    <form method="post" class="layui-form" id="loginForm">
        <input name="userName" placeholder="用户名" type="text" lay-verify="required" class="layui-input">
        <hr class="hr15">
        <input name="password" lay-verify="required" placeholder="密码" type="password" class="layui-input">
        <hr class="hr15">
        <input value="登录" lay-submit lay-filter="login" style="width:100%;" type="button" id="loginBtn">
        <hr class="hr20">
        <p class="errorMsg"></p>
    </form>
</div>

<script>
    $(function () {
        $("#loginBtn").click(function () {
            $(this).val("登录中");
            $(this).attr("disabled", "disabled");
            $(".errorMsg").text("");
            var _this = $(this);
            var url = "<%=basePath %>login?" + $('#loginForm').serialize();
            $.ajax({
                type: "POST",
                async: true,
                url: url,
                // data: data,
                processData: false,
                contentType: false,
                success: function () {
                    location.href = "<%=basePath %>";
                },
                statusCode: {
                    401: function () {
                        againLogin(_this, "用户名或密码错误");
                    },
                    403: function () {
                        againLogin(_this, "该帐号不允许登录");
                    }
                }
            });
        });

        $(document).keypress(function (e) {
            // 回车键事件
            if (e.which == 13) {
                $("#loginBtn").click();
            }
        });
    });

    function againLogin(_this, text) {
        _this.val("登录");
        _this.removeAttr("disabled");
        $(".errorMsg").show(300);
        $(".errorMsg").text(text);
    }
</script>
</body>
</html>
